<?php

namespace Viettrans\FrontBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Viettrans\FrontBundle\Entity\User
 *
 * @ORM\Table(name="user")
 * @ORM\HasLifecycleCallbacks()
 * @ORM\Entity(repositoryClass="Viettrans\FrontBundle\Entity\UserRepository")
 */
class User {
/*******************************************************************************
* Begin of user's definitions
*******************************************************************************/
    private $locality;
    private $confirmPassword;
	private $newPassword;
	private $confirmNewPassword;
	private $currentPassword;
	
    public function getLocality() {
        return $this->locality;
    }
    
    public function setLocality($locality) {
        $this->locality = $locality;
    }

    public function getConfirmPassword() {
        return $this->confirmPassword;
    }
    
    public function setConfirmPassword($confirmPassword) {
        $this->confirmPassword = $confirmPassword;
    }

    public function getNewPassword() {
        return $this->newPassword;
    }
    
    public function setNewPassword($newPassword) {
        $this->newPassword = $newPassword;
    }

    public function getConfirmNewPassword() {
        return $this->confirmNewPassword;
    }
    
    public function setConfirmNewPassword($confirmNewPassword) {
        $this->confirmNewPassword = $confirmNewPassword;
    }
	
    public function getCurrentPassword() {
        return $this->currentPassword;
    }
    
    public function setCurrentPassword($currentPassword) {
        $this->currentPassword = $currentPassword;
    }
	
    public function getTownObj() {
        return $this->town;
    }

    /**
    * @ORM\OneToMany(targetEntity="Announcement", mappedBy="user")
    */
    protected $announcements;
    
    /**
    * @ORM\ManyToOne(targetEntity="Town", inversedBy="users")
    * @ORM\JoinColumn(name="townId", referencedColumnName="id")
    */
    protected $town;
	 
	/**
    * @Assert\True(message = "Mật khẩu xác nhận không đúng.")
    */
	public function isConfirmPasswordMatched() {
		return ($this->password == $this->confirmPassword);
	}
	
    /**
    * @ORM\prePersist
    */
    public function setDefaultValues() {
		$now = new \DateTime();
	
        if (!isset($this->createdAt)) $this->createdAt = $now;
        
		if (!isset($this->isActivated)) $this->isActivated = false;
    }
/*******************************************************************************
* End of user's definitions
*******************************************************************************/    
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=50)
     * @Assert\NotBlank(message="Tên liên hệ không được để trống.")
     * @Assert\MaxLength(limit=50, message="Tên liên hệ tối đa là 50 kí tự.")
     */
    private $name;

    /**
     * @var integer $townId
     *
     * @ORM\Column(name="townId", type="integer")
     */
    private $townId;	
	
    /**
     * @var string $email
     *
     * @ORM\Column(name="email", type="string", length=100)
     * @Assert\NotBlank(message="Email liên hệ không được để trống.")
     * @Assert\MaxLength(limit=100, message="Email liên hệ tối đa là 100 kí tự.")
     * @Assert\Regex(pattern="/^[-a-z0-9!#$%&'*+\/=?^_`{|}~]+(\.[-a-z0-9!#$%&'*+\/=?^_`{|}~]+)*@(([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){1,63}\.)+([a-z0-9]([-a-z0-9]*[a-z0-9]+)?){2,63}$/i", message="Email không hợp lệ.")
     */
    private $email;
	
    /**
     * @var string $telephone
     *
     * @ORM\Column(name="telephone", type="string", length=15, nullable=true)
     * @Assert\Regex(pattern="/^\d{8,15}$/", message="Điện thoại không hợp lệ (8-15 số).")
     */
    private $telephone;

    /**
     * @var string $password
     *
     * @ORM\Column(name="password", type="text", length=20)
     */
    private $password;

    /**
     * @var bool $isActivated
     *
     * @ORM\Column(name="isActivated", type="boolean")
     */
    private $isActivated;	

    /**
     * @var bool $createdAt
     *
     * @ORM\Column(name="createdAt", type="datetime")
     */
    private $createdAt;
	
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set townId
     *
     * @param integer $townId
     */
    public function setTownId($townId) {
        $this->townId = $townId;
    }

    /**
     * Get townId
     *
     * @return integer 
     */
    public function getTownId() {
        return $this->townId;
    }
	
    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set email
     *
     * @param string $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set telephone
     *
     * @param string $telephone
     */
    public function setTelephone($telephone)
    {
        $this->telephone = $telephone;
    }

    /**
     * Get telephone
     *
     * @return string 
     */
    public function getTelephone()
    {
        return $this->telephone;
    }

    /**
     * Set password
     *
     * @param string $password
     */
    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }
	
	/**
     * Set isActivated
     *
     * @param bool
     */
    public function setIsActivated($isActivated)
    {
        $this->isActivated = $isActivated;
    }

    /**
     * Get isActivated
     *
     * @return bool 
     */
    public function getIsActivated()
    {
        return $this->isActivated;
    }
	
	/**
     * Set createdAt
     *
     * @param datetime
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;
    }

    /**
     * Get createdAt
     *
     * @return bool 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }	
}